package com.qhg.saas_server.controller;


import com.qhg.saas_server.MyException.roadNotFindExcepiton;
import com.qhg.saas_server.annotation.Mylog;
import com.qhg.saas_server.empty.Result;
import com.qhg.saas_server.pojo.dto.RoadDto;
import com.qhg.saas_server.service.RoadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

@RestController
@RequestMapping("/road")
@Api(tags = "路线管理表接口")
@Slf4j
@CrossOrigin
public class RoadController {

    @Autowired

    RoadService roadService;

    @ApiOperation("根据条件查询路线信息列表")
    @PostMapping("/list")
    public Result getRoadListByCondition(@RequestBody
            @ApiParam("hashMap 接收参数：pageSize，pageNum，roadName,comploName,sortMode<排序方式 0代表按时间升序，1代表按照时间降序")
                                             HashMap<String,Object> hashMap){

        return  roadService.getRoadListByCondition(hashMap);

    }


    @ApiOperation("根据路线Id,查询路线的详细信息")
    @GetMapping("/{roadId}")
    public Result getRoadDetailsByRoadId(@PathVariable("roadId") Integer roadId) throws roadNotFindExcepiton {

       return  roadService.getRoadDetailsByRoadId(roadId);

    }

    @ApiOperation("添加路线信息")
    @PostMapping("/add")
    public Result  addRoad(@RequestBody RoadDto roadDto){

        return  roadService.addRoad(roadDto);
    }

    @ApiOperation("删除路线信息")
    @DeleteMapping("/{roadId}")
    @Mylog("删除路线信息")
    public Result deleteRoad(@PathVariable("roadId") Integer roadId){

      return   roadService.deleteRoad(roadId);

    }

    @ApiOperation("跟新路线信息")
    @PutMapping
    @Mylog("跟新路线信息")
    public  Result updateRoad(@RequestBody RoadDto roadDto) {

       return   roadService.updateRoad(roadDto);

    }


    @ApiOperation("删除路线中的全部商店节点信息")
    @DeleteMapping("/roadDetils/{roadId}")
    @Mylog("删除路线中的全部商店节点信息")
    public Result clearAllRoadDetils(@PathVariable Integer roadId){

        roadService.clearAllRoadDetils(roadId);
        return Result.success("清除成功");

    }


    @ApiOperation("删除路线中单个的节点信息")
    @DeleteMapping("/deleteRoadDetil")
    @Mylog("删除路线中单个的节点信息")
    public Result deleteRoadDetil(@RequestParam("roadId") Integer roadId,
                                  @RequestParam("storeId") Integer storeId){

        roadService.deleteRoadDetil(roadId,storeId);
        return  Result.success("删除成功");

    }


}
